<template>
  <view>
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" circular>
      <swiper-item v-for="item in Banners" :key="item.goods_id">
        <image :src="item.image_src" @click="navigator(item.goods_id)"></image>
      </swiper-item>
    </swiper>
    <view>
      <view class="navbox">
        <view class="nav-item" @click="switchFn(item.name)" v-for="item,index in Navlist" :key="index">
          <image :src="item.image_src"></image>
        </view>
      </view>
    </view>
    <view class="floorlist">
      <view class="flooritem" v-for="item,index in Floorlist" :key="index">
        <image class="floortitle" :src="item.floor_title.image_src" />
        <view class="grid">
          <image :data-url="i.navigator_url" v-for="i,index in item.product_list" @click="navigatorTo"
            :key="i.image_src" :class="{griditem:true,spanrow:index===0}" :src="i.image_src"
            :style="{width:i.image_width+'rpx'}" mode="widthFix" />
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    getBanners,
    getNavlist,
    getFloorlist
  } from '@/api/home.js'
  export default {
    data() {
      return {
        Banners: [],
        Navlist: [],
        Floorlist: []
      };
    },
    methods: {
      navigator(id) {
        uni.navigateTo({
          url: '/subpkg/goods_detail/goods_detail?goods_id=' + id
        })
      },
      async AgetBanners() {
        const res = await getBanners()
        this.Banners = res.message
        // console.log(res);
      },
      switchFn(name) {
        if (name === '分类') {
          uni.switchTab({
            url: "/pages/cate/cate"
          })
        }
      },
      async AgetNavlist() {
        const res = await getNavlist()
        this.Navlist = res.message
      },
      async AgetFloorlist() {
        const res = await getFloorlist()
        console.log(res);
        this.Floorlist = res.message

      },
      navigatorTo(e) {
        console.log(e.currentTarget.dataset.url.split('?')[1]);
        uni.navigateTo({
          url: '/subpkg/goods_list/goods_list?' + e.currentTarget.dataset.url.split('?')[1]
        })
      }
    },
    onLoad() {
      this.AgetBanners()
      this.AgetNavlist()
      this.AgetFloorlist()















    }
  }
</script>

<style lang="scss">
  swiper {
    height: 330rpx;

    swiper-item,
    swiper-item image {
      width: 100%;
      height: 100%;
    }
  }

  .navbox {
    width: 100%;
    height: 140rpx;
    background-color: pink;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    // align-items: center;

    .nav-item {
      text-align: center;
      width: 100%;
      height: 140rpx;
    }

    .nav-item image {
      width: 128rpx;
      height: 140rpx;

    }
  }

  .floorlist {
    .floortitle {
      height: 60rpx;
      width: 100%;
      display: flex;
    }

    .grid {
      display: grid;
      grid-template-rows: repeat(2, 1fr);
      grid-template-columns: repeat(3, 1fr);
      gap: 3px;
      // justify-content:space-between;

      .griditem {
        background-color: pink;
      }

      .spanrow {
        grid-row: span 2;
      }
    }
  }
</style>
